package com.classeven.downhill.object;

import com.classeven.downhill.define.GameData;
import com.classeven.downhill.define.iDefine_Object;
import com.classeven.downhill.element.AScene;
import com.classeven.downhill.element.ASprite;
import com.classeven.downhill.engine.Anchor;
import com.classeven.downhill.engine.GameEngine;
import com.classeven.downhill.engine.Utils;

public class Obstacle {

	Obstacle_Element obs[] = null;
	int count;
	float starty;
	GameEngine engine;
	

		
	public Obstacle(GameEngine engine, int count, float startY)
	{
//		int a = GameData.GAME_ARENA;
//		int b = GameData.GAME_ARENA_LEVEL;
//		int length = 0;
		
//		for(int i=0; i < iDefine_Object.OBS_LEVEL[a][b].length; i++)
//		{
//			length += iDefine_Object.OBS_LEVEL[a][b][i];
//		}
		
		obs = new Obstacle_Element[count];
		
		for(int i=0; i < count; i++)
		{
			Utils.TRACE("ini wes peng "+i);
			
//			if(iDefine_Object.OBS_LEVEL[a][b][0] <= i+1 && iDefine_Object.OBS_LEVEL[a][b][0] != 0)
//			{
			obs[i] = new Obstacle_Element(engine, iDefine_Object.ancor[Utils.GetRandomInRange(0, iDefine_Object.ancor.length -1)], startY,
					iDefine_Object.distance[Utils.GetRandomInRange(0, iDefine_Object.distance.length -1)],Utils.GetRandomInRange(0, iDefine_Object.OBS_.length - 1));
//			}
			
		}
		this.engine = engine;
		this.count = count;
		this.starty = startY;		
	}
	
	public void update(AScene scene, float speed)
	{
		for(int i=0; i < count; i++)
		{
			obs[i].update(Utils.GetRatio(speed));
			

		}
		
		
	}
	
	public void reborn()
	{
		for(int i=0; i < count; i++)
		{
			Utils.TRACE("ini wes peng "+i);
			
			obs[i] = new Obstacle_Element(engine, iDefine_Object.ancor[Utils.GetRandomInRange(0, iDefine_Object.ancor.length -1)], starty,
					iDefine_Object.distance[Utils.GetRandomInRange(0, iDefine_Object.distance.length -1)], Utils.GetRandomInRange(0, iDefine_Object.OBS_.length - 1));
		
			
		}
	}
	
	public void attach(AScene scene)
	{
		for(int i=0; i < count; i++)
		{
			scene.theScene().attachChild(obs[i].getObs().theSprite());
		}
	}
}
